package com.wangshidai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangshidai.entity.SysUser;
import com.wangshidai.service.SysUserService;
import com.wangshidai.mapper.SysUserMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static sun.plugin2.os.windows.FLASHWINFO.size;

/**
 *
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
    implements SysUserService{
    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public Page getUserList(Integer c, Integer s,Integer id, String username) {
        Page page = new Page(c,s);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("dept_id",id);

        if (username!=null) {
            wrapper.like("login_name",username);
        }
        sysUserMapper.selectMapsPage(page, wrapper);
        return page;
    }

    @Override
    public Boolean saveUser(SysUser sysUser) {
        boolean state = false;
        //调用服务层方法查询待添加的用户是否存在(用户名,电话,邮箱不允许重复),不存在则插入,否则返回
        if(sysUserMapper.isUserExist(sysUser).size()==0){
            sysUserMapper.insert(sysUser);
            state = true;
        }
        return state;
    }

    @Override
    public Boolean updateUser(SysUser sysUser) {
        boolean state = false;

        List<SysUser> userList = sysUserMapper.isUserExist(sysUser);
        if (userList.size()==0) {
            sysUserMapper.updateById(sysUser);
            state = true;
        }
        return state;
    }
}




